import java.util.Scanner;

public class code1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = 0;
        int b = 1;
        int c = 0;
        while(true) {
            c = a + b;
            if(c>n) {
                break;
            }
            a = b;
            b = c;
        }
        System.out.println(Math.min(n-b,c-n));
    }
}
